<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>

<link type="text/css" rel="stylesheet"  href="static/css/phone.css"/>
	<body>
		<div id="lay4">商品详情</div>
		<div id="lay5">
			<div class="a">手机名称:</div>
			<div class="b">${goods.gname}<%-- <input type="text" name="search" value="${goods.gname}"/> --%></div>
		</div>
		<div id="lay5">
			<div class="a">价格:</div>
			<div class="b">${goods.price}<%-- <input type="text" name="search" value="${goods.price}"/> --%></div>
		</div>
		<div id="lay5">
			<div class="a">网络类型:</div>
			<div class="b">${goods.wangluo}<%-- <input type="text" name="search" value="${goods.wangluo}"/> --%></div>
		</div>
		<div id="lay5">
			<div class="a">机身颜色:</div>
			<div class="b">${goods.color}<%-- <input type="text" name="search" value="${goods.color}"/> --%></div>
		</div>
		<div id="lay5">
			<div class="a">存储容量:</div>
			<div class="b">${goods.rongliang}<%-- <input type="text" name="search" value="${goods.rongliang}"/> --%></div>
		</div>
		<div id="lay5">
			<div class="a">处理器:</div>
			<div class="b">${goods.chuliqi}<%-- <input type="text" name="search" value="${goods.chuliqi}"/> --%></div>
		</div>
		<div id="lay5">
			<div class="a">电池容量:</div>
			<div class="b">${goods.dainchi}<%-- <input type="text" name="search" value="${goods.dainchi}"/> --%></div>
		</div>
		<div id="lay5">
			<div class="a">像素:</div>
			<div class="b">${goods.xiangsu}<%-- <input type="text" name="search" value="${goods.xiangsu}"/> --%></div>
		</div>
		<div id="lay6">
			<div class="d"><input type="button" value="立即购买" /></div>
			<div class="c"><input type="button" value="加入购物车" onclick="addCat(${goods.gid})" /> </div>
		</div>
		<script type="text/javascript">
		function addCat(gid) {
			var xhr=new XMLHttpRequest();//创建对象
			xhr.open("get","cart?action=add&id="+gid);//请求方式和URL
			xhr.send();//发送请求
			xhr.onreadystatechange=function(){
				if(xhr.readyState==4&&xhr.status==200){
					var res=xhr.responseText;
					res=JSON.parse(res);
					
					//是否需要登录
					if(res.code==-1){
						//跳转登录页面
						window.location.href="login.jsp";
    					return ;
					}else if(res.code==0){
						//如果已登录，则显示加入购物车
						alert(res.data);
					}
				}
			}
		}
		</script>
</body>
</html>